<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * This builder can build a object based on xml similar to this:
 * <poco:name>
 *   <poco:givenName>Darren</poco:givenName>
 *   <poco:familyName>Bounds</poco:familyName>
 * </poco:name>
 * 
 * 
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */
class Mm_Atom_Element_Poco_Name_Builder extends Mm_Xml_Element_Builder_Abstract {
    
    protected $optionalChildElements = array(
        array('key' => Mm_Atom_Element_Poco_Name::ELEMENT_GIVENNAME, 'type' => 1, 'builder' => 'Mm_Atom_Element_Poco_GivenName', 'xpath_query' => '/poco:name/poco:givenName'),
        array('key' => Mm_Atom_Element_Poco_Name::ELEMENT_FAMILYNAME, 'type' => 1, 'builder' => 'Mm_Atom_Element_Poco_FamilyName', 'xpath_query' => '/poco:name/poco:familyName'),
    );
    
    public function __construct($rawXML) {
        $this->rawXML = $rawXML;
    }
    
    /**
     * @return Mm_Atom_Element_ActivityStream_Subject
     */
    public function build() {
        $this->parseChildElementsFromRawXML();
        return new Mm_Atom_Element_Poco_Name($this->childElements);
    }
}